Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cast tuple of filenames to list to improve error handling #12891

Merged
merged 1 commit into from
Oct 9, 2024

Conversation

mscheltienne
Copy link
Member

@mscheltienne mscheltienne commented Oct 9, 2024

@sappelhoff Is this better? c.f. #12843 (comment)

Now:

# %%
from pathlib import Path
import numpy as np
import mne

# create a dummy raw
sampling_freq = 1000
times = np.linspace(0, 1, sampling_freq, endpoint=False)
sine = np.sin(20 * np.pi * times)
cosine = np.cos(10 * np.pi * times)
data = np.array([sine, cosine])
info = mne.create_info(
    ch_names=["10 Hz sine", "5 Hz cosine"], ch_types=["misc"] * 2, sfreq=sampling_freq
)
raw = mne.io.RawArray(data, info)

# I want to set raw.filenames
a = Path.cwd() / "IDoNotExist.jpg"

# previous error: TypeError: 'tuple' object does not support item assignment
# new error: FileNotFoundError: File <...>/IDoNotExist.jpg not found.
raw.filenames = (a,)

# this gives the right error: FileNotFoundError: File <...>/IDoNotExist.jpg not found.
raw.filenames = [a]

# this works correctly
#path_to_file_that_exists = ...
#raw.filenames = [path_to_file_that_exists]

# this works, no errors raised (which is ok, because I am using a private attribute to circumvent checks)
raw._filenames = (a,)

@drammock drammock enabled auto-merge (squash) October 9, 2024 19:50
Copy link
Member

@sappelhoff sappelhoff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks a lot!

@drammock drammock merged commit 06050bc into mne-tools:main Oct 9, 2024
30 checks passed
@mscheltienne mscheltienne deleted the caast branch October 10, 2024 08:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants